package maplearn;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class Demo {
	
	public static void main(String[] args) {
		Map<String, Integer> map = new HashMap<>();
		map.put("banana", 1);
		map.put("apple", 2);
		map.put("pear", 3);
		
		//遍历方式一：
		Iterator<Entry<String, Integer>> iterator = map.entrySet().iterator();
		while(iterator.hasNext()) {
			Map.Entry<String, Integer> entry = iterator.next();
			System.out.println("key: "+entry.getKey()+" value: "+entry.getValue());
		}
		
		
		//遍历方式二：
		Set<String> keySet = map.keySet();
		Iterator<String> iterator2 = keySet.iterator();
		
		while(iterator2.hasNext()) {
			Object key = iterator2.next();
			System.out.println("key: "+ key);
			System.out.println("value: "+map.get(key));
		}
		
		//遍历方式三：单纯的遍历value
		Collection<Integer> c = map.values();
		Iterator<Integer> iterator3 = c.iterator();
		while(iterator3.hasNext()) {
			Object value = iterator3.next();
			System.out.println("value: "+value);
		}
		
		
		//hashMap 并不是对hashcode做模运算,而是 h & (length-1)
		System.out.println(Integer.toBinaryString(2));
		System.out.println(Integer.toBinaryString(31));
		System.out.println(89 & 15);
		System.out.println(1 << 30);
		System.out.println(Integer.MAX_VALUE);
	}
	

}
